package ru.neoflex.chugunov.algorithm;

import ru.neoflex.chugunov.Word;

public class SM2 {
	  public static final int QUALITY_SUBTRACTOR = 5;
	  public static final float E_FACTOR_TOP = 2.5f;
	  public static final float E_FACTOR_FLOOR = 1.3f;
	  public static final int INTERVAL_FLOOR = 1;

	  public static void scoreCard(Word w, int quality) {
	      float qFactor = (QUALITY_SUBTRACTOR - quality);
	      float newFactor = w.geteFactor() + (0.1f - qFactor * (0.08f + qFactor * 0.02f));
	      if (newFactor < E_FACTOR_FLOOR) {
	          newFactor = E_FACTOR_FLOOR;
	      }
	      w.seteFactor(newFactor);
	  }

	  public static void calculateInterval(Word word) {
	      int interval = word.getInterval();
	      if (word.geteFactor() < 3f) {
	          word.setCount(1);
	      }
	      int count = word.getCount();
	      if (count == 2) {
	          interval = 6;
	      } else if (count > 2) {
	         interval =  Math.round(word.getInterval() * word.geteFactor());
	      }
	      word.setInterval(interval);
	  }

	  public static void scoreCardAndCalculateInterval(Word word, int quality) {
	          scoreCard(word, quality);
	          calculateInterval(word);
	  }
}
